<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
          name="viewport">
    <meta content="ie=edge" http-equiv="X-UA-Compatible">
    <title>Document</title>
    <script th:src="@{/static/layui/layui.js}"></script>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<body>
<div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-demo="getChecked" type="button">获取选中节点数据</button>
    <button class="layui-btn layui-btn-sm" lay-demo="setChecked" type="button">全选</button>
    <button class="layui-btn layui-btn-sm" lay-demo="reload" type="button">全不选</button>
</div>

<textarea class="layui-textarea" name="">

</textarea>
<div class="demo-tree-more" id="test12"></div>
</body>

<script th:inline="javascript">
    layui.use(['tree', 'util'], function () {
        var tree = layui.tree
            , layer = layui.layer
            , util = layui.util
            , $ = layui.jquery

        //模拟数据
        var demoId1 = [];
        var tt = [];
        var t;
        $.ajax({
            url: '/data',
            type: 'GET',
            contentType: 'application/json; charset=UTF-8',
            dataType: "json",
            success: function (res) {
                console.log("==========================================");
                console.log(res);
            }
        })


        //按钮事件
        util.event('lay-demo', {
            getChecked: function (othis) {
                let checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                console.log(checkedData);
                layer.alert(JSON.stringify(checkedData), {shade: 0});
                console.log(checkedData);
            }
            , setChecked: function () {
                tree.setChecked('demoId1', demoId1); //勾选指定节点
            }
            , reload: function () {
                //重载实例
                tree.reload('demoId1', {});
                tt = [];

            }

        });
    })
</script>


</html>